<?php
header("Content-type: text/html; charset=utf-8");
$appid = 'wxexxxxxxb66'; //自己填写
$secret = '2b2d0xxxxxxxxxxxcc30'; //自己填写
//$ACCESS_TOKEN = "ebp81dmMEDRwRgAA2gZVnDhRXssar3WZaFJJ-b9kBj5_RoPvZRMDdjo9NGCjDM4x_jFjYJ7SmNDFddQ3Ckcv6w0t7bkEb4LYn_LuZuBKJrxVwBJ38CYQwe8fxYYy5aMKpMTyBU681SvYQoIUA3cJ3w";
//josn数据  一级的只能3个以下  二级只能是5个以下
$data = ' {
     "button":[
     {	
         
          "name":"会员中心",
          "sub_button":[
			{
               "type":"click",
               "name":"绑定会员",
               "key":"CLICK_V01001"
            },
            {
               "type":"click",
               "name":"在线购卡",
               "key":"CLICK_V01002"
            },
            {
               "type":"click",
               "name":"会员充值",
               "key":"CLICK_V01003"
            }
            ]
      },
      {
       
           "name":"活动中心",
        "sub_button":[
            {
               "type":"click",
               "name":"最新活动",
               "key":"CLICK_V02001"
            },
            {
               "type":"click",
               "name":"往日活动",
               "key":"CLICK_V02002"
            }
            ]
      },
      {
           "name":"公司介绍",
           "sub_button":[
            {
               "type":"click",
               "name":"公司介绍",
               "key":"CLICK_V03001"
            },
            {
               "type":"click",
               "name":"联系客服",
               "key":"CLICK_V03002"
            }
            ]   
       }
       ]
 }
';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
$jsoninfo = json_decode($tmpInfo,true);
var_dump($jsoninfo);
if(!$jsoninfo['access_token']){
	echo '错误编号：'.$jsoninfo['errcode'].',详细：'.$tmpInfo;
	exit();
}
$ACCESS_TOKEN = $jsoninfo['access_token'];
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$ACCESS_TOKEN}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfos = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Errno' . curl_error($ch);
}
curl_close($ch);
var_dump($tmpInfos);
?>
